package com.yonyougov.devops.cruxcisupport.app;

import com.yonyougov.devops.cruxcisupport.app.dto.AppPageLikeDto;
import com.yonyougov.devops.cruxcisupport.app.dto.LinkAppDto;
import com.yonyougov.devops.cruxcisupport.app.vo.LinkAppVo;
import com.yonyougov.devops.cruxcisupport.app.vo.NoLinkAppByRoleIdDto;
import com.yonyougov.devops.cruxcisupport.app.vo.NoLinkAppVo;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;

/**
 * t_app数据层实现
 */
@Repository
public class AppDaoImpl extends BaseDaoImpl<AppEntity, BigInteger> implements AppDao {
    //<!--用户自定义代码开始-->
    private final SqlSessionTemplate sqlSessionTemplate;

    public AppDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public List<AppEntity> findPageByRoleIds(AppPageLikeDto appPageLikeReqVo) {
        String statement = AppEntity.class.getName() + "Mapper.findPageByRoleIds";
        return sqlSessionTemplate.selectList(statement, appPageLikeReqVo);
    }

    @Override
    public int countByRoleIds(AppPageLikeDto appPageLikeDto) {
        String statement = AppEntity.class.getName() + "Mapper.countByRoleIds";
        return sqlSessionTemplate.selectOne(statement, appPageLikeDto);
    }


    /**
     * 根据角色查未关联的应用
     *
     * @param noLinkAppByRoleIdDto com.yonyougov.devops.cruxcisupport.app.vo.NoLinkAppByRoleIdDto
     * @return com.yonyougov.devops.cruxcisupport.app.vo.NoLinkAppVo
     */
    @Override
    public List<NoLinkAppVo> findNoLinkAppListByRoleId(NoLinkAppByRoleIdDto noLinkAppByRoleIdDto) {
        String statement = AppEntity.class.getName() + "Mapper.findAllAppNoLinkByRoleId";
        return sqlSessionTemplate.selectList(statement, noLinkAppByRoleIdDto);
    }

    @Override
    public List<LinkAppVo> findAppByRoleIds(LinkAppDto linkAppDto) {
        String statement = AppEntity.class.getName() + "Mapper.findLinkApp";
        return sqlSessionTemplate.selectList(statement, linkAppDto);
    }

    @Override
    public List<AppEntity> findById(List<BigInteger> ids) {
        String statement = AppEntity.class.getName() + "Mapper.findById";
        HashMap<Object, Object> map = new HashMap<>();
        map.put("ids", ids);
        return sqlSessionTemplate.selectList(statement, map);
    }

    /**
     * 根据角色查未关联的应用
     *
     * @param noLinkAppByRoleIdDto com.yonyougov.devops.cruxcisupport.app.vo.NoLinkAppByRoleIdDto
     * @return int
     */
    @Override
    public int countNoLinkAppByRoleId(NoLinkAppByRoleIdDto noLinkAppByRoleIdDto) {
        String statement = AppEntity.class.getName() + "Mapper.countByAllAppNoLinkByRoleId";
        return sqlSessionTemplate.selectOne(statement, noLinkAppByRoleIdDto);
    }

    @Override
    public AppEntity findByPrimaryKey(BigInteger id) {
        String statement = AppEntity.class.getName() + "Mapper.findByPrimaryKey";
        return sqlSessionTemplate.selectOne(statement, id);
    }

    //<!--用户自定义代码结束-->
}
